

/**
 * 后处理扩散圆  半径不能过大  不然会闪烁
 */

import CircleScanShader from '../shader/CircleScanShader.glsl?raw'
// import CircleScanShader from '../shader/WaterReflectShader.glsl?raw'
import { v4 as uuid } from 'uuid'

export default class CircleScan {
  /**
   * 
   * @param {*} viewer 
   * @param {*} positions 
   * @param {*} radius 
   * @param {*} options 
   */  
  
  constructor(viewer , positions , radius , options = {}){
    this._viewer = viewer
    this._delegate = undefined
    this._position = positions
    this._radius = radius || 10.0
    this._speed = options.speed || 1.0
    this._color = options.color || Cesium.Color.DEEPSKYBLUE
  } 


  mounted(){
    
    let center = this._position
    let up = Cesium.Ellipsoid.WGS84.geodeticSurfaceNormal(
      center,
      new Cesium.Cartesian3()
    )
    let self = this
    this._delegate = new Cesium.PostProcessStage({
      name: uuid(),
      fragmentShader: CircleScanShader,
      uniforms: {
        centerWC: function() {
          return center
        },
        normalWC: function() {
          return up
        },
        radius: function() {
          return self._radius
        },
        speed: function() {
          return self._speed
        },
        color: function() {
          return self._color
        }
      }
    })
  }

  /**
   * 添加后处理效果
   * @returns 
   */

  start(){
    !this._delegate && this.mounted()
    
    this._delegate && this._viewer.scene.postProcessStages.add(this._delegate)
    return this
  }

  /**
   * 停止渲染
   */

  stop(){
    this._delegate && this._viewer.scene.postProcessStages.remove(this._delegate)
    this._delegate = undefined
  }

}
